package com.lhy.mymall.utils;

import org.apache.tomcat.util.codec.binary.Base64;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author: 卢辉宇
 * @date: 2022/12/13 15:32
 * @description: MD5（加密）工具
 */
public class MD5Util {
    /*定义一个随机敲的盐值*/
    private static String salt="hjlk/.'[-9y7";
    public static String getMD5Str(String str) throws NoSuchAlgorithmException {
        //得到MD5工具
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        //MD5工具开始加密
        byte[] bytes = md5.digest((str+salt).getBytes());
        //变回64位的string类型并返回
        return Base64.encodeBase64String(bytes);
    }
}
